﻿using System;
using System.Collections.Generic;
using System.Linq;
using Pap.Data.Abstraction.Utils;

namespace Pap.Data.LToS.Repositories
{
    /// <summary>
    /// 
    /// </summary>
    public class ImageRepository : IImageRepository
    {
        /// <summary>
        /// 
        /// </summary>
        IDatabase _Database;

        #region IImageRepository Members

        /// <summary>
        /// Initializes a new instance of the <see cref="ImageRepository"/> class.
        /// </summary>
        /// <param name="database">The database.</param>
        public ImageRepository(IDatabase database)
        {
            _Database = database;
        }

        /// <summary>
        /// Gets the image.
        /// </summary>
        /// <param name="imageID">The image ID.</param>
        /// <returns></returns>
        public IImage GetImage(Guid imageID)
        {
            return _Database.Images.SingleOrDefault(image => image.ImageID == imageID);
        }

        /// <summary>
        /// Inserts the image.
        /// </summary>
        /// <param name="image">The image.</param>
        public void InsertImage(IImage image)
        {
            this._Database.Insert<IImage>(image);
        }
        /// <summary>
        /// Inserts the images.
        /// </summary>
        /// <param name="images">The images.</param>
        public void InsertImages(IEnumerable<IImage> images)
        {
            this._Database.InsertAll<IImage>(images);
        }

        /// <summary>
        /// Finds the image.
        /// </summary>
        /// <param name="where">The where.</param>
        /// <returns></returns>
        public IEnumerable<IImage> FindImage(System.Linq.Expressions.Expression<Func<IImage, bool>> where)
        {
            return this._Database.Images.Where(where);
        }


        /// <summary>
        /// Gets the image types.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<ILookUpEntity> GetImageTypes()
        {
            return this._Database.ImageTypes;
        }

        /// <summary>
        /// Deletes the image.
        /// </summary>
        /// <param name="imageId">The image id.</param>
        public void DeleteImage(Guid imageId)
        {
            this._Database.Delete<IImage>(GetImage(imageId));
        }

        /// <summary>
        /// Deletes the images.
        /// </summary>
        /// <param name="lst">The LST.</param>
        public void DeleteImages(IEnumerable<IImage> lst)
        {
            this._Database.DeleteAll<IImage>(lst);
        }

        #endregion
    }
}
